package com.itheima.controller;

import com.github.pagehelper.PageHelper;
import com.itheima.aop.Log;
import com.itheima.entity.*;
import com.itheima.service.StudentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description StudentController
 * @Author 你的名字拼接或昵称
 * @Date 2025-09-06
 */

@RestController
@RequestMapping("/students")
@Slf4j
public class StudentController {

    @Autowired
    private StudentService studentService;

    //分页查询
    @GetMapping
    public Result page(StudentQueryParam studentQueryParam){
        PageBean pageBean = studentService.page(studentQueryParam);
        return Result.success(pageBean);
    }

    //新增学生信息
    @Log
    @PostMapping
    public Result save(@RequestBody Student student){
       studentService.save(student);
       return Result.success();
    }

    //根据id查询学生
    @GetMapping("/{id}")
    public Result getid(@PathVariable Integer id){
        Student student = studentService.getid(id);
        return Result.success(student);
    }

    //修改学生信息
    @Log
    @PutMapping
    public Result update(@RequestBody Student student){
        studentService.update(student);
        return Result.success();
    }

    //删除学生信息
    @Log
    @DeleteMapping("/{ids}")
    public Result delete(@PathVariable List<Integer> ids){
        studentService.delete(ids);
        return Result.success();
    }
    //违纪处理
    @Log
    @PutMapping("/violation/{id}/{score}")
    public Result updateviolation(@PathVariable Integer id,
                                  @PathVariable Integer score){
        studentService.updateviolation(id,score);
        return Result.success();
    }
}
